package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MesMaterialRequisition;
import com.ruoyi.system.service.IMesMaterialRequisitionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 领料单Controller
 * 
 * @author ruoyi
 * @date 2024-11-14
 */
@RestController
@RequestMapping("/system/requisition")
public class MesMaterialRequisitionController extends BaseController
{
    @Autowired
    private IMesMaterialRequisitionService mesMaterialRequisitionService;

    /**
     * 查询领料单列表
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesMaterialRequisition mesMaterialRequisition)
    {
        startPage();
        List<MesMaterialRequisition> list = mesMaterialRequisitionService.selectMesMaterialRequisitionList(mesMaterialRequisition);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 导出领料单列表
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:export')")
    @Log(title = "领料单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesMaterialRequisition mesMaterialRequisition)
    {
        List<MesMaterialRequisition> list = mesMaterialRequisitionService.selectMesMaterialRequisitionList(mesMaterialRequisition);
        ExcelUtil<MesMaterialRequisition> util = new ExcelUtil<MesMaterialRequisition>(MesMaterialRequisition.class);
        util.exportExcel(response, list, "领料单数据");
    }

    /**
     * 获取领料单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesMaterialRequisitionService.selectMesMaterialRequisitionById(id));
    }

    /**
     * 新增领料单
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:add')")
    @Log(title = "领料单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesMaterialRequisition mesMaterialRequisition)
    {
        return toAjax(mesMaterialRequisitionService.insertMesMaterialRequisition(mesMaterialRequisition));
    }

    /**
     * 修改领料单
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:edit')")
    @Log(title = "领料单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesMaterialRequisition mesMaterialRequisition)
    {
        return toAjax(mesMaterialRequisitionService.updateMesMaterialRequisition(mesMaterialRequisition));
    }

    /**
     * 删除领料单
     */
    @PreAuthorize("@ss.hasPermi('system:requisition:remove')")
    @Log(title = "领料单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesMaterialRequisitionService.deleteMesMaterialRequisitionByIds(ids));
    }
}
